{{csrf_field()}}
<div class="layui-row">
    <div class="layui-col-md8">
        <div class="layui-form-item">
            <label class="layui-form-label">* 标题</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" lay-reqText="请输入标题" id="title" name="title" value="{{$info->title?? old('title')}}" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">别名</label>
            <div class="layui-input-block">
                <input type="text" id="post_slug" name="post_slug" value="{{$info->post_slug?? old('post_slug')}}" autocomplete="off" placeholder="" class="layui-input">
                <div class="layui-form-mid layui-word-aux">根据标题自动生成 拼音或者英文单词 用‘-’连接 用于URL中</div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">详情内容</label>
            <div class="layui-input-block">
                <textarea id="post_content"  name="post_content">{{$info->post_content ?? old('post_content')}}</textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">跳转链接</label>
            <div class="layui-input-block">
                <input type="text" name="post_jump_url"  value="{{$info->post_jump_url?? old('post_jump_url')}}"  autocomplete="off" placeholder="" class="layui-input">
                <div class="layui-form-mid layui-word-aux">如填写则跳到目标网站 例如：https://juejin.im/</div>
            </div>
        </div>

    </div>
    <div class="layui-col-md4">

        <div class="layui-form-item">
            <label class="layui-form-label">* 父页面</label>
            <div class="layui-input-block">

                <select  name="parent_id" xm-select-direction="down" xm-select="select1" xm-select-search-type="dl" xm-select-search xm-select-radio="">
                    @foreach($pages as $key =>$val)
                        @if(isset($info->id) && $val['id'] != $info->id)
                            <option value="{{$val['id']}}" @if(isset($checkArr) && in_array($val['id'],$checkArr)) selected @endif>{{$val['cat_name']}}</option>
                        @else
                            <option value="{{$val['id']}}" @if(isset($checkArr) && in_array($val['id'],$checkArr)) selected @endif>{{$val['cat_name']}}</option>
                        @endif
                    @endforeach
                </select>

            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label ">封面</label>
            <div class="layui-input-block">
                <button type="button"  class="layui-btn upload-image">上传图片</button>
                <div class="layui-upload-list">

                    @if(isset($info->logo) && !empty($info->logo))
                        <img class="layui-upload-img" src="{{$info->post_thumb?? ''}}" style="width: 90px" >
                    @else
                        <img class="layui-upload-img" style="width: 90px" >
                    @endif
                    <input type="hidden" name="post_thumb" value="{{$info->post_thumb?? ''}}">
                </div>

            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">发布时间：</label>
            <div class="layui-input-block">
                <input type="text" name="post_date"   value="{{$info->post_date ?? old('post_date')}}" autocomplete="off" placeholder="" class="layui-input date">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序：</label>
            <div class="layui-input-block">
                <input type="number" name="post_sort" autocomplete="off" placeholder=""  value="{{$info->post_sort ?? old('post_sort')}}" class="layui-input">
                <div class="layui-form-mid layui-word-aux">数字越小越靠前</div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态：</label>
            <div class="layui-input-block">
                <select name="post_status">
                    <option value="">请选择所属分类</option>
                    <option value="1" selected="selected"> 前端开发</option>
                    <option value="2" > 后端开发</option>
                    <option value="3" > 移动互联</option>
                    <option value="4" > 人工智能</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">访问密码：</label>
            <div class="layui-input-block">
                <input type="text" name="post_password" autocomplete="off" placeholder="" class="layui-input">
                <div class="layui-form-mid layui-word-aux">默认空，无密码可访问</div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">自定模板：</label>
            <div class="layui-input-block">
                <select name="post_template">
                    <option value="">自定模板</option>
                    <option value="1" selected="selected"> 前端开发</option>
                    <option value="2" > 后端开发</option>
                    <option value="3" > 移动互联</option>
                    <option value="4" > 人工智能</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-filter="post-submit" lay-submit>保 存</button>
                <button class="layui-btn" lay-filter="*" lay-submit="">预 览</button>
                <button class="layui-btn layui-btn-primary" type="reset">重 置</button>
            </div>
        </div>

    </div>
</div>
<textarea id="edit_image" style="display: none;"></textarea>
@section('script')
    <link rel="stylesheet" href="{{ asset('static/admin/css/formSelects-v4.css') }}">
    <script>
        UE.getEditor('post_content',{
            // initialFrameWidth :800,// 设置编辑器宽度
            initialFrameHeight:400,// 设置编辑器高度
            scaleEnabled:true
        });

    </script>

    <script>
        layui.use(['layer', 'form','jquery','formSelects','strpy'], function(){
            var layer = layui.layer,
                form =layui.form,

                $  = layui.jquery;



            var _editor = UE.getEditor("edit_image",{
                initialFrameWidth:800,
                initialFrameHeight:300,
                zIndex:19891026,
            });
            _editor.ready(function (){
                _editor.hide();
                _editor.addListener('beforeInsertImage',function(t,arg){
                    console.log(arg);
                    console.log(t);
                    var obj = _editor.queryCommandValue("serverparam");
                    if(obj.type == "upload-image"){
                        if(arg.length>1){
                            layer.msg("最多只能选择1张图片，请重新选择");
                            return false;
                        }
                        if(arg.length>0) {
                            var uploadImageTd = obj.uploadImageItem.parent().find(".layui-upload-list");
                            console.log(uploadImageTd);
                            uploadImageTd.find('img').attr('src',arg[0].src);
                            uploadImageTd.find('input').val(arg[0].image_id);
                            uploadImageTd.show();
                        }else{
                            layer.msg("请先选择图片");
                            return false;
                        }
                    }
                    return true;
                });
            });

            $("body").on("click", ".upload-image", function () {

                //此处进行初始化
                var obj = _editor.queryCommandValue("serverparam");
                obj.type = "upload-image";
                obj.uploadImageItem = $(this);
                var uploadImage = _editor.getDialog("insertimage");
                console.log(obj);
                uploadImage.open();
            });

            $("#title, #post_slug").change(function(){
                var strpy= layui.strpy($(this).val(),'-');
                $('#post_slug').val(strpy.replace(/\ /g, "-"));
            });



        });
    </script>
@endsection